package com.daqsoft.controller.system;

import com.daqsoft.dto.GeneralResultEnum;
import com.daqsoft.permission.Verify;
import com.daqsoft.permission.VerifyType;
import com.daqsoft.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周麟东 on 11:44
 */
@RestController
@RequestMapping("permissionManager")
@Verify(desc = "权限管理")
public class PermissionManageController {

    @Autowired
    private PermissionService permissionService;

//    @RequestMapping("getMethodPermissions")
//    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "获取全部操作权限")
//    public GeneralResultEnum getMethodPermissionsByGroupId(int groupId){
//        return GeneralResultEnum.SUCCESS.setData(permissionService.getMethodPermissionByGroupId(groupId));
//    }
    @RequestMapping("getModulePermissions")
    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "获取全部用户组权限")
    public GeneralResultEnum getModulePermissionsByGroupId(int groupId){
        return GeneralResultEnum.SUCCESS.setData(permissionService.getGroupModulePermissionTree(groupId));
    }
//
//    @RequestMapping("saveGroupMethodPermission")
//    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "保存用户组操作权限  ")
//    public GeneralResultEnum saveMethodPermission(int groupId , @RequestParam("permission[]") String [] methodName){
//        permissionService.saveGroupMethodPermission(groupId,methodName);
//        return GeneralResultEnum.SUCCESS;
//    }
    @RequestMapping("saveGroupModulePermission")
    @Verify(value = VerifyType.HAVE_PERMISSION,desc = "保存用户组权限  ")
    public GeneralResultEnum saveModulePermission(int groupId , @RequestParam("modules[]") int [] moduleId , @RequestParam("configId[]") int [] configId){
        permissionService.saveGroupModulePermission(groupId,moduleId);
        permissionService.saveGroupConfigPermission(groupId,configId);
        return GeneralResultEnum.SUCCESS;
    }
}
